﻿
namespace HSS.Interlink.Web
{
	/// <summary>
	/// Defines the contract for a Server-Side file cache.
	/// </summary>
	public interface IFileCache
	{
		/// <summary>
		/// Gets or sets if auto purging is enabled.
		/// </summary>
		bool AutoPurge { get; set; }
		/// <summary>
		/// Adds the provided file bytes to the file cache.
		/// </summary>
		/// <param name="fileName">The name of the file being cached.</param>
		/// <param name="content">The file contents to cache.</param>
		/// <returns>The absolute path the temp file.</returns>
		string Add(string fileName, byte[] content);
		/// <summary>
		/// Adds the provided <see cref="System.Web.HttpRequest"/> <c>InputStream</c> to the file cache.
		/// </summary>
		/// <param name="fileName">The name of the file being cached.</param>
		/// <param name="request">The <see cref="System.Web.HttpRequest"/> to cache.</param>
		/// <returns>The absolute path the temp file.</returns>
		string Add(string fileName, System.Web.HttpRequest request);
		/// <summary>
		/// Determines if the provided file name exists in the cache.
		/// </summary>
		/// <param name="fileName">The name of the file to check for existence.</param>
		/// <returns>true if the file exists; otherwise false.</returns>
		bool Exists(string fileName);
		/// <summary>
		/// Gets the absolute path to a file contained in the cache.
		/// </summary>
		/// <param name="fileName">The name of the file to retrieve.</param>
		/// <returns>The absolute path of the requested file if it exists; otherwise an empty string.</returns>
		string GetFilePath(string fileName);
		/// <summary>
		/// Trys to get the absolute path for the requested file if it exists.
		/// </summary>
		/// <param name="fileName">The name of the file to retrieve.</param>
		/// <param name="filePath">An OUT parameter that will contain the absolute path of the requested file if it exists in the cache; otherwise an empty string.</param>
		/// <returns>true if the file exists and the absolute path resolved to an actual file on disk; otherwise false.</returns>
		bool TryGetFilePath(string fileName, out string filePath);
		/// <summary>
		/// Enumerates the files currently in the cache.
		/// </summary>
		/// <returns>An enumerable collection of file names in the cache.</returns>
		System.Collections.Generic.IEnumerable<string> EnumerateCache();
		/// <summary>
		/// Requests a purge cycle to be processed.
		/// </summary>
		void QueueAutoPurge();
	}
}